//
//  KABExhibitionModel.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/10.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABExhibitionModel.h"

@implementation KABExhDetGuestItem
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{@"guest_id" : @"id"};
}
@end
@implementation KABExhDetTicketItem
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{@"ticket_id" : @"id"};
}
@end


@implementation KABExhListItem
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{@"exhibition_id" : @"id"};
}
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"special_guest_list" : [KABExhDetGuestItem class],
             @"exhibition_ticket_list" : [KABExhDetTicketItem class]};
}

- (NSInteger)selOriginalPrice {
    KABExhDetTicketItem * item = [self selTicketItem];
    if (item) {
        return item.original_price;
    }
    
    return self.exhibition_ticket_list.firstObject.original_price;
}

- (NSInteger)selDiscountedPrice {
    KABExhDetTicketItem * item = [self selTicketItem];
    if (item) {
        return item.discounted_price;
    }
    
    return self.exhibition_ticket_list.firstObject.discounted_price;
}
- (NSInteger)selMaxTicketCnt {
    KABExhDetTicketItem * item = [self selTicketItem];
    if (item) {
        return MIN(self.limited, item.stock);
    }
    
    return MIN(self.limited, self.exhibition_ticket_list.firstObject.stock);
}
- (NSInteger)selStock {
    KABExhDetTicketItem * item = [self selTicketItem];
    if (item) {
        return item.stock;
    }
    
    return self.exhibition_ticket_list.firstObject.stock;
}
- (NSString *)selTicketType {
    KABExhDetTicketItem * item = [self selTicketItem];
    if (item) {
        return item.content;
    }
    
    return self.exhibition_ticket_list.firstObject.content;
}
- (KABExhDetTicketItem *)selTicketItem {
    for (KABExhDetTicketItem * item in self.exhibition_ticket_list) {
        if (item.ticket_id == self.ticket_id) {
            return item;
        }
    }
    return nil;
}
- (NSInteger)totalPrice {
    return self.number * self.selOriginalPrice;
}
- (NSString *)priceTypeDesStr {
    NSMutableString *mStr = [NSMutableString string];
    [self.exhibition_ticket_list enumerateObjectsUsingBlock:^(KABExhDetTicketItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *str = [NSString stringWithFormat:@"%@%.2f元；", obj.content, obj.original_price / 100.0];
        [mStr appendString:str];
    }];
    if (mStr.length) {
        [mStr deleteCharactersInRange:NSMakeRange(mStr.length - 1, 1)];
    }
    return mStr;
}
@end

@implementation KABExhibitionModel
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }

+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"exhibition_list" : [KABExhListItem class]};
}
- (BOOL)totalLoad {
    return (self.exhibition_list.count >= self.total_rows);
}
- (void)addMoreWithData:(KABExhibitionModel *)temp {
    self.total_rows = temp.total_rows;
    [self.exhibition_list addObjectsFromArray:temp.exhibition_list];
}
@end




//@implementation KABExhDetail
//@end



@implementation KABExhOrderDetail
+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{@"orderId" : @"id"};
}
@end
@implementation KABExhOrderListItem
+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper {
    return @{@"orderId" : @"id",
             @"exhName" : @"exhibition_name",
             @"exhCoverImgUrl" : @"exhibition_cover_image_url"};
}
@end
@implementation KABExhibitionOrder
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"exhibition_order_list" : [KABExhOrderDetail class]};
}
- (BOOL)totalLoad {
    return (self.exhibition_order_list.count >= self.total_rows);
}
- (void)addMoreWithData:(KABExhibitionOrder *)temp {
    self.total_rows = temp.total_rows;
    [self.exhibition_order_list addObjectsFromArray:temp.exhibition_order_list];
}
@end



@implementation KABExhOrderCheckResult
@end



@implementation KABExhSearchItem
@end
@implementation KABExhSearchList
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"exhibition_list" : [KABExhSearchItem class]};
}
- (BOOL)totalLoad {
    return (self.exhibition_list.count >= self.total_rows);
}
- (void)addMoreWithData:(KABExhSearchList *)temp {
    self.total_rows = temp.total_rows;
    [self.exhibition_list addObjectsFromArray:temp.exhibition_list];
}
@end

